﻿//jQuery扩展
//$.QueryString["ppp"]
//$.addQueryString({"key":"value"});
jQuery.extend({
    'QueryString':
         window.location.search.length <= 1 ?
            new Object() : function (a) {
                var b = new Object();
                for (var i = 0; i < a.length; ++i) {
                    var p = a[i].split('=');
                    if (p[0] == "_") {
                        continue;
                    }
                    b[p[0]] = decodeURIComponent(p[1]);
                }
                return b;
            }
         (window.location.search.substr(1).split('&')),
    'addQueryString': function (keyValues) {
        return this.param(this.extend({}, this.QueryString, keyValues));
    },
    //页面数据变量缓存
    //getVarFun 通常为获取对象的ajax方法
    'CacheVarSetting': function (varName, getVarFun) {
        var f = $(document).data("VarFun");
        if (!f) {
            f = new Object();
        }
        f[varName] = getVarFun;
        $(document).data("VarFun", f);
    },
    'GetCacheVar': function (varName, key1, key2, key3, key4) {
        var dataKey = varName;
        if (key1) {
            dataKey += "|" + key1;
        }
        if (key2) {
            dataKey += "|" + key2;
        }
        if (key3) {
            dataKey += "|" + key3;
        }
        if (key4) {
            dataKey += "|" + key4;
        }
        var v = $(document).data(dataKey);
        if (v) {
            return v;
        }
        else {
            var f = $(document).data("VarFun");
            if (!f) {
                return null;
            }
            if ($.isFunction(f[varName])) {
                return f[varName].call(window, key1, key2, key3, key4);
            }
            else {
                return null;
            }
        }
    }
});